package com.pat.service;

import java.util.List;

import javax.ws.rs.Consumes;
import javax.ws.rs.DELETE;
import javax.ws.rs.GET;
import javax.ws.rs.POST;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import javax.ws.rs.core.MediaType;
import javax.ws.rs.core.Response;

import com.pat.manager.ContactManager;
import com.pat.om.Contact;

@Path("/contacts")
public class ContactService {

	private ContactManager contactMgr = new ContactManager();

	/**
	 * Get all the contact information from provided mobile number
	 * 
	 * @return the list of the contact information
	 */
	@GET
	@Path("/{contactId}")
	@Produces({ MediaType.APPLICATION_JSON })
	public List<Contact> get(@PathParam("contactId") String contactId) {
		return contactMgr.get(contactId);
	}

	/**
	 * To add a new contact
	 * 
	 * @param contact
	 *            Contact instance
	 * @return
	 */
	@POST
	@Path("/contact")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response add(Contact contact) {
		contactMgr.post(contact);
		return Response.status(201).entity(contact).build();
	}

	/**
	 * @param regId
	 */
	@DELETE
	@Path("/contact/{contactId}/{friendCellNo}")
	@Consumes(MediaType.APPLICATION_JSON)
	public Response delete(@PathParam("contactId") String contactId,
			@PathParam("friendCellNo") String friendCellNo) {
		int result = contactMgr.delete(contactId, friendCellNo);
		if (result > 0) {
			return Response.status(200).entity(String.valueOf(result)).build();
		} else {
			return Response.status(304).entity(0).build();
		}
	}
}
